import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import { NavBar, Icon, ActionSheet } from 'antd-mobile'
import axios from 'axios'

// import Header from '@c/header/Header'
import PersonalInfoUi from '../ui/PersonalInfoUi'


@withRouter
class PersonalInfo extends Component {
    
    handleInfoClick = props => {
        return () => {
            this.props.history.push('/name',props)
        }
    }

    handleImgClick = props => {
        return () => {
            this.props.history.push('/portrait',props )
        }
    }

    handleEmerClick = props => {
        return () => {
            this.props.history.push('/emergency', props)
        }
    }

    handleAccountClick = props => {
        return () => {
            this.props.history.push('/account', props)
        }
    }
    handleQRcodeClick = img => {
        return () => {
            this.props.history.push('/qrcode', { img })
        }
    }

    state = {
        sex: JSON.parse(sessionStorage.username).sex,
        age: JSON.parse(sessionStorage.username).age,
        zhiwei:JSON.parse(sessionStorage.username).zhiwei
    }


    showActionSheet = props => {
        return () => {
            const BUTTONS = props;
            ActionSheet.showActionSheetWithOptions({
                options: BUTTONS,
                cancelButtonIndex: BUTTONS.length - 1,
                // destructiveButtonIndex: BUTTONS.length - 2,
                maskClosable: true,
            },
                (buttonIndex) => {
                    if (buttonIndex === BUTTONS.length - 1) return
                    switch (props[0]) {
                        case '男':
                            this.setState({ sex: BUTTONS[buttonIndex] });
                            break;
                        case '1年以内':
                            this.setState({ age: BUTTONS[buttonIndex] });
                            break;
                        case '教师':
                            this.setState({ zhiwei: BUTTONS[buttonIndex] });
                            break;
                        default:
                            break;
                    }
                });
        }
    }

    handleChangeClick (){
        let infoList = JSON.parse(sessionStorage.username);
        console.log(infoList);
         axios.post('http://10.9.65.195:8080/update',infoList)
            .then(function(responst){
                console.log(responst);
            })
            .catch(err => console.log(err))
    }

    componentDidMount() {
        // let infoList = JSON.parse(sessionStorage.username).usUser.sex;
        // console.log(infoList);
        this.forceUpdate()
    }
    

    render() {

        return (
            <div>
                <NavBar
                    mode="dark"
                    icon={<Icon type="left" />}
                    onLeftClick={() => this.props.history.goBack()}
                    rightContent={[
                        <i
                            key="0"
                            onClick={this.handleChangeClick}
                        >确认</i>
                    ]}
                >个人信息</NavBar>
                <PersonalInfoUi
                    state={this.state}

                    list={this.props}
                    onInfoClick={this.handleInfoClick}
                    onImgClick={this.handleImgClick}
                    onEmerClick={this.handleEmerClick}
                    onAccountClick={this.handleAccountClick}
                    onQRcodeClick={this.handleQRcodeClick}
                    onBtnClick={this.showActionSheet}
                ></PersonalInfoUi>
            </div>
        )
    }

}

export default PersonalInfo
